<template>
    <div class="app-container">
      <Levelbar></Levelbar>
      <div class="main" v-loading = "loading">
            <div class="form-title">发放情况</div>
            <el-form ref="form" :model="form" label-width="110px" class="form-pading">
                <aside>基础信息</aside>
                <el-row :gutter="21">
                    <el-col :span="7">
                        <el-form-item label="采购单号">
                            <span class="title-left">{{form.basisObj.flowNum}}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item label="经销商">
                            <span class="title-left">{{form.basisObj.orguserName}}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item label="手机号">
                            <span class="title-left">{{form.basisObj.phone}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="21">
                    <el-col :span="7">
                        <el-form-item label="学校名称">
                            <span class="title-left">{{form.basisObj.schoolName}}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="14">
                        <el-form-item label="硬件开通情况">
                            <!-- <span class="title-left">{{form.sServiceName}}</span> -->
                            <el-row :gutter="21">
                                <el-col :span="5">
                                    <span>e直播</span>
                                    <span v-if="form.basisObj.isElive == 1" class="onText">已开通</span>
                                    <span v-else class="offText">未开通</span>
                                </el-col>
                                <el-col :span="5">
                                    <span>空中课堂</span>
                                    <span v-if="form.basisObj.isAirclass == 1" class="onText">已开通</span>
                                    <span v-else class="offText">未开通</span>
                                </el-col>
                                <el-col :span="5">
                                    <span>报平安</span>
                                    <span v-if="form.basisObj.isPingan == 1" class="onText">已开通</span>
                                    <span v-else class="offText">未开通</span>
                                </el-col>
                                <el-col :span="5">
                                    <span>家校通</span>
                                    <span v-if="form.basisObj.isContact == 1" class="onText">已开通</span>
                                    <span v-else class="offText">未开通</span>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>
                </el-row>
                <aside>发放汇总</aside>
                <div class="m-height">
                    <el-row :gutter="20">
                        <el-col :span="15">
                            <table class='table' align="left">
                                <tr>
                                    <td align="center">卡券类型</td>
                                    <td align="center">卡券服务期限</td>
                                    <td align="center">待发放</td>
                                    <td align="center">已发放</td>
                                    <td align="center">待使用</td>
                                    <td align="center">已使用</td>
                                </tr>
                                <tr v-for="item in form.priceInformation" :key="item">
                                    <td align="center">{{fifter(item.serviceTypeId)}}</td>
                                    <td align="center">{{item.month || '--'}}</td>
                                    <td align="center">{{item.readyNum}}</td>
                                    <td align="center">{{item.sendNum}}</td>
                                    <td align="center">{{item.notUseNum}}</td>
                                    <td align="center">{{item.useNum}}</td>
                                </tr>
                            </table>
                            <div class="tableState" v-if="form.tableState">暂无数据</div>
                        </el-col>
                    </el-row>
                </div>
                <aside>发放详情</aside>
                <el-row :gutter="21">
                    <el-col :span="6">
                        <el-form-item label="卡券类型">
                            <el-select v-model="form.carValue" placeholder="请选择" style="width:100%">
                                <el-option v-for="item in form.carList" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="手机号">
                            <el-input v-model="form.tel" style="width:100%"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="使用状态">
                            <el-select v-model="form.startValue" placeholder="请选择" style="width:100%">
                                <el-option v-for="item in form.startList" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="">
                            <el-button type="primary" class="top-btn" @click="onSubmit">查询</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-table :data="form.dataTable" border style="width: 100%" ref="multipleTable" v-loading="tableLoading">
                    <el-table-column type="index" width="50" label="序号" align="center"></el-table-column>
                    <el-table-column label="卡券类型" align="center" prop="serviceType">
                      <template scope="scope">
                        {{fifter(scope.row.serviceType)}}
                      </template>
                    </el-table-column>
                    <el-table-column label="卡券ID" align="center" prop="cardId">
                      <template scope="scope">
                        {{scope.row.cardId || '--'}}
                      </template>
                    </el-table-column>
                    <el-table-column label="发放手机号" align="center" prop="sendPhone">
                      <template scope="scope">
                        {{scope.row.sendPhone || '--'}}
                      </template>
                    </el-table-column>
                    <el-table-column label="发放时间" align="center" prop="sendTime">
                      <template scope="scope">
                        {{scope.row.sendTime || '--'}}
                      </template>
                    </el-table-column>
                    <el-table-column label="使用状态" align="center" prop="status">
                      <template scope="scope">
                        {{scope.row.status == 0 ? '未使用' : scope.row.status == 1 ? '已使用' : scope.row.status == 2 ? '未发放' : '--'}}
                      </template>
                    </el-table-column>
                    <el-table-column label="使用时间" align="center" prop="useTime">
                      <template scope="scope">
                        {{scope.row.useTime || '--'}}
                      </template>
                    </el-table-column>
                </el-table>
                <div class="pagination-container">
                  <el-pagination layout="total, sizes, prev, pager, next, jumper" :total="pageQuery.total" :current-page.sync="pageQuery.currentpage" :page-sizes="config.pageSizes" :page-size="config.pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange">
                  </el-pagination>
              </div>
            </el-form>
            <el-form label-width="100px" class = "form-pading">
            </el-form>
            <footer>
                <el-row type = "flex" class = "row-bg" justify = "center">
                    <el-col :span="2">
                        <el-button @click="go">返回</el-button>
                    </el-col>
                </el-row>
            </footer>
      </div>
  </div>
</template>
<script>
import Levelbar from '../../layout/Levelbar';
import {
  getPurchaseCardBaseinfo,
  listPurchaseCardSummary,
  pagePurchaseCardByPurchaseId
} from 'api/serviceManage';
import { mapState, mapActions, mapGetters } from 'vuex';
export default {
    name: 'addService',
    components: { Levelbar },
    computed: {
        ...mapState({
            config: state => state.config.table
        }),
        ...mapGetters(['uid'])
    },
    data() {
        return {
            rules: {
                sMoney: [
          { required: true, message: '内容不能为空' },
          { pattern: /^[0-9]\d*$/, message: '请输入正整数' }
                ]
            },
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() < Date.now() - 8.64e7;
                }
            },
            loading: false,
            tableLoading: false,
            pageQuery: {
                currentpage: 1,
                total: 0
            },
            form: {
                basisObj: {},
                dataTable: [],
                priceInformation: [],
                carList: [
                    {
                        label: '请选择',
                        value: ''
                    },
                    {
                        label: 'e直播',
                        value: '123547'
                    },
                    {
                        label: '报平安',
                        value: '123552'
                    },
                    {
                        label: '空中课堂',
                        value: '123551'
                    },
                    {
                        label: '家校通',
                        value: '123553'
                    },
                    {
                        label: '会员',
                        value: '123554'
                    }
                ],
                carValue: '',
                startList: [
                    {
                        label: '请选择',
                        value: ''
                    },
                    {
                        label: '未使用',
                        value: '0'
                    },
                    {
                        label: '已使用',
                        value: '1'
                    },
                    {
                        label: '未发放',
                        value: '2'
                    }
                ],
                tableState: false,
                startValue: '',
                tel: ''
            }
        };
    },
    created() {
        this.init();
        this.search()
    },
    methods: {
    // 全局获取行数
        ...mapActions(['ChangePageSize']),
    // 分页
        handleSizeChange(val) {
            this.pageQuery.currentpage = 1;
            this.ChangePageSize(val);
            this.search();
        },
        handleCurrentChange(val) {
            this.pageQuery.currentpage = val;
            this.search();
        },
        go() {
            this.$router.go(-1);
        },
        init() {
            this.loading = true;
            getPurchaseCardBaseinfo(this.$route.params.id)
        .then(data => {
            this.form.basisObj = data.data.content;
        })
        .then(data => {
            listPurchaseCardSummary(this.$route.params.id).then(data => {
                if (data.data.content.length !==0) {
                    this.form.tableState = false;
                } else {
                    this.form.tableState = true;
                }
                this.form.priceInformation = data.data.content;
                this.loading = false;
            });
        })
        .catch(() => {
            this.loading = false;
        });
        },
        fifter(v) {
            switch (v) {
                case '123547':
                    return 'e直播';
                case '123552':
                    return '报平安';
                case '123551':
                    return '空中课堂';
                case '123553':
                    return '家校通';
                case '123554':
                    return '会员';
                default:
                    return '--'
            }
        },
        search() {
            this.tableLoading = true;
            pagePurchaseCardByPurchaseId(
              this.$route.params.id, 
              this.form.carValue,
              this.form.tel,
              this.form.startValue,
              this.pageQuery.currentpage,
              this.config.pageSize
              ).then(data => {
                  this.tableLoading = false;
                  this.form.dataTable = data.data.content.list;
                  this.pageQuery.total = data.data.content.pagination.total;
              }).catch(() => {
                  this.tableLoading = false;
              })
        },
        onSubmit() {
            this.pageQuery.currentpage = 1;
            this.search()
        }
    }
};
</script>
<style lang="scss" scoped>
.pagination-container{
  text-align: right;
}
.m-height {
  overflow: hidden;
}
.table {
  margin-bottom: 20px;
  text-align: left;
  th,
  td {
    padding: 0 20px;
    width: 200px;
    height: 40px;
    font-size: 14px;
  }
  a {
    font-size: 15px;
    color: #ff5e2c;
  }
}
.title-left {
  margin-left: 10px;
}
.monty-icon {
  padding-left: 0 !important;
}
.el-icon-plus {
  color: #ff5e2c;
}
.title-icon {
  color: #999;
}
.title-center {
  text-align: center;
}
.title {
  padding-top: 30px;
  font-size: 20px;
}
footer {
  padding: 20px 0 40px;
}
i {
  cursor: pointer;
}
.main {
  padding: 0 50px;
  background: #fff;
  box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
  -webkit-box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
  .form-title {
    padding-top: 8px;
    text-align: center;
    font-size: 18px;
    color: #333;
    line-height: 72px;
    font-weight: bold;
    font-family: Microsoft YaHei;
    border-bottom: 1px solid #ddd;
  }
}
.tableState{
  text-align: center;
  color: #666;
  font-size: 14px;
}
aside {
  position: relative;
  padding: 36px 0 0 20px;
  font-size: 14px;
  color: #333;
  margin-bottom: 40px;
  &::before {
    height: 14px;
    width: 4px;
    background: #ff5e2c;
    content: "";
    position: absolute;
    left: 0;
    bottom: 4px;
  }
}
.onText {
  color: #666;
}
.b-title {
  font-size: 14px;
  margin-bottom: 15px;
  display: block;
}
.offText {
  color: #ff0000;
}
input {
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: #fff;
  background-image: none;
  border-radius: 2px;
  border: 1px solid rgb(217, 200, 191);
  box-sizing: border-box;
  color: rgb(61, 41, 31);
  display: inline-block;
  font-size: inherit;
  height: 36px;
  line-height: 1;
  outline: none;
  padding: 3px 10px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 100%;

  &:focus {
    outline: none;
    border-color: #ff5e2c;
  }
}
</style>
